﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using G.Navigate;

namespace G.Reader.View.Book
{
    public partial class ChooseReadProgressPage : GBasePage
    {
        public ChooseReadProgressPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            double p = double.Parse(this.NavigationContext.QueryString["progress"]);
            this.looping_1.DataSource = new Data.IntLoopingDataSource() { MinValue = 0, MaxValue = 100 };
            this.looping_1.DataSource.SelectedItem = (int)p;
            this.looping_2.DataSource = new Data.IntLoopingDataSource() { MinValue = 0, MaxValue = 10 };
            this.looping_2.DataSource.SelectedItem = ((int)(p * 10)) % 10;
            this.looping_3.DataSource = new Data.IntLoopingDataSource() { MinValue = 0, MaxValue = 10 };
            this.looping_3.DataSource.SelectedItem = ((int)(p * 100)) % 10;
        }

        protected override void OnNavigatingFromBack(NavigateBackFromEventArgs e)
        {
            base.OnNavigatingFromBack(e);
            if (!string.IsNullOrEmpty(p))
            {
                e.HasHandle = true;
                e.Param = p;
            }
        }
        private string p = string.Empty;
        private void btnOK_Click(object sender, EventArgs e)
        {
            p = string.Format("{0}.{1}{2}", looping_1.DataSource.SelectedItem, looping_2.DataSource.SelectedItem, looping_3.DataSource.SelectedItem);
            this.NavigationService.GoBack();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.NavigationService.GoBack();
        }
    }
}